local skel = fk.CreateSkill {
  name = "emo__yaoge",
}

Fk:loadTranslationTable{
  ["emo__yaoge"] = "邀戈",
  [":emo__yaoge"] = "准备阶段，你可以令一名其他角色交给你一张牌，你本回合下次使用的牌必须为此牌。",

  ["#emo__yaoge-choose"] = "邀戈：令1名其他角色交给你1张牌，你本回合下次使用的牌必须为此牌",
  ["#emo__yaoge-give"] = "邀戈：请交给 %src 一张牌",
  ["@@emo__yaoge-turn"] = "邀戈",

  ["$emo__yaoge1"] = "将军愿守坚城不动，我只知杀敌为功。",
  ["$emo__yaoge2"] = "铁锥敲牙，咬齿保全乎？须得反钳！",
}

skel:addEffect(fk.EventPhaseStart, {
  anim_type = "control",
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and player.phase == Player.Start
    and table.find(player.room.alive_players, function (p)
      return p ~= player and not p:isNude()
    end)
  end,
  on_cost = function (self, event, target, player, data)
    local targets = table.filter(player.room:getOtherPlayers(player, false), function (p) return not p:isNude() end)
    if #targets == 0 then return false end
    local tos = player.room:askToChoosePlayers(player, {
      min_num = 1, max_num = 1, targets = targets, skill_name = skel.name,
      prompt = "#emo__yaoge-choose",
    })
    if #tos > 0 then
      event:setCostData(self, {tos = tos})
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).tos[1]
    if not to then return end
    local cid = room:askToCards(to, {
      min_num = 1, max_num = 1,include_equip = true, cancelable = false, skill_name = skel.name,
      prompt = "#emo__yaoge-give:" .. player.id ,
    })[1]
    if not cid then return end
    room:setPlayerMark(player, "@@emo__yaoge-turn", cid)
    room:obtainCard(player, cid, false, fk.ReasonGive, to, skel.name)
  end,
})

skel:addEffect(fk.CardUsing, {
  can_refresh = function (self, event, target, player, data)
    return target == player and player:getMark("@@emo__yaoge-turn") ~= 0
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player, "@@emo__yaoge-turn", 0)
  end,
})

skel:addEffect("prohibit", {
  prohibit_use = function(self, player, card)
    local cid = player:getMark("@@emo__yaoge-turn")
    if cid ~= 0 then
      local cards = Card:getIdList(card)
      return not (#cards == 1 and cards[1] == cid)
    end
  end,
})

return skel
